package 华为机试8月23日;

import java.util.Scanner;

public class 华为第三题完整版 {

    private static final String set = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            String[] a = s.split("\\s+");
            System.out.println(func(a[0], a[1], a[2]));
        }
        sc.close();
    }

    private static String func(String r1, String r2, String s) {
        int dec = sour2Dec(r1, s);
        String res = dec2Dest(r2, dec);
        return res.replaceAll("^[0]+", "");
    }

    private static String dec2Dest(String r2, int dec) {
        int div = Integer.parseInt(r2);
        StringBuilder sb = new StringBuilder();
        while (dec != 0) {
            sb.append(set.charAt(dec % div));
            dec = dec / div;
        }
        return sb.reverse().toString();
    }

    private static int sour2Dec(String r1, String s) {
        int dec = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            dec += set.indexOf(s.charAt(i)) * Math.pow(Integer.parseInt(r1), (s.length() - 1) - i);
        }
        return dec;
    }
}
